<script setup>
    import { ref } from 'vue'
    import { useRouter } from 'vue-router';
    import { Plus } from '@element-plus/icons-vue'
    import chatInput from '../../components/chatInput/index.vue'
    import MarkdownView from '../../components/MarkdownView/index.vue'

    const router = useRouter();
    const dialogVisible = ref(true);

    const aiMessage = ref(`Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, wor!Hello, world!Hello, world!Hello, world!Hello, world!Hello, wor!Hello, world!Hello, world!Hello, world!Hello, world!Hello, wor!Hello, world!Hello, world!Hello, world!Hello, world!Hello, wor!Hello, world!Hello, world!Hello, world!Hello, world!Hello, wor!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!Hello, world!`);
    const url = ref(`https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg`);

</script>

<template>
    <div>
        <div class="head-content">
            <ArrowLeft class="head-icon" @click="router.back()" />
        </div>
        <div class="configuration-content">
            <div class="card-box content-left">
                <div class="box2-title">配置</div>
                <div class="box2-content">
                    AI模型
                    <el-select v-model="value" style="width: 82%;" placeholder="请选择">
                        <el-option label="deepseek" value="deepseek" />
                        <el-option label="deepseek" value="deepseek" />
                    </el-select>
                </div>
                <div class="box2-content">提示词</div>
                <el-input v-model="textarea" class="box2-textarea" :rows="4" type="textarea" />
                <div class="box2-title" style="margin-top: 30px;">
                    关联知识库
                    <el-button :icon="Plus" type="primary" plain>选择</el-button>
                </div>
                <div class="df-aic">
                    <div class="box2-library">
                        <img src="../../assets/image/icon/collection-icon.png" />
                        知识库名称
                    </div>
                </div>
                <el-button type="primary" class="sub-button">保存</el-button>
            </div>
            <div class="card-box content-right">
                <div class="right-title">调试预览</div>
                <div class="overflow-none chat-message-list">
                    <div class="user-message">
                        <div class="message-test">为什么成年人比小孩更害怕犯错？</div>
                    </div>
                    <div class="ai-message">
                        <el-image class="ai-avatar" :src="url" fit="cover" />
                        <div class="ai-test">
                            <MarkdownView :content="aiMessage"></MarkdownView>
                        </div>
                    </div>
                </div>
                <chatInput chatType="newChat" />
            </div>
        </div>
        <!-- popup-content -->
        <el-dialog v-model="dialogVisible" title="绑定知识库">
            <div class="checked-content">
                <div class="checked-box action" v-for="item in 6" :key="item">
                    <img src="../../assets//image//icon/collection-icon.png" />
                    <div class="checked-name">知识库名称</div>
                    <Delete width="16px" color="red" />
                </div>
            </div>
            <div class="checked-title">知识库列表</div>
            <div class="checked-content">
                <div class="checked-box" v-for="item in 6" :key="item">
                    <img src="../../assets//image//icon/collection-icon.png" />
                    <div class="checked-name">知识库名称</div>
                </div>
            </div>
        </el-dialog>
    </div>
</template>

<style scoped lang="scss">
    .checked-title {
        color: #000;
        font-weight: bold;
        padding-left: 10px;
        margin: 20px 0;
    }

    .checked-content {
        display: flex;
        flex-wrap: wrap;
        align-items: center;

        .checked-box {
            width: calc(22% - 10px);
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 6px 10px;
            border-radius: 9px;
            margin: 0 7px 10px;
            box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.08);

            img {
                width: 30px;
            }

            .checked-name {
                flex: 1;
                margin-left: 4px;
            }

            &.action {
                background-color: #C5D7FF;
            }
        }
    }

    .sub-button {
        width: 90%;
        height: 40px;
        margin-top: 40px;
        position: absolute;
        left: 5%;
        bottom: 20px;
    }

    .configuration-content {
        width: 95%;
        margin: 0 auto;
        display: flex;
        position: relative;
        align-items: center;
        justify-content: space-between;

        .card-box {
            border-radius: 8px;
            background: #FFFFFF;
            box-shadow: 0px 0px 7px 0px rgba(0, 0, 0, 0.08);
        }

        .content-left,
        .content-right {
            width: calc(60% - 50px);
            height: 81vh;
            padding: 0 20px;
            position: relative;
        }

        .content-left {
            width: calc(40% - 50px);

            .box2-title {
                margin: 30px 20px 20px;
                font-size: 16px;
                font-weight: bold;
                color: #000000;
                display: flex;
                align-items: center;
                justify-content: space-between;
            }

            .box2-content {
                font-size: 14px;
                color: rgba(0, 0, 0, 0.5);
                margin: 0 20px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 20px;
            }

            .box2-textarea {
                width: calc(100% - 40px);
                margin: 0 20px 20px;
            }

            .box2-library {
                color: #000;
                font-weight: bold;
                font-size: 16px;
                margin-left: 20px;
                border-radius: 9px;
                border: 1px solid #DEDEDE;
                display: flex;
                align-items: center;
                justify-content: center;
                padding: 10px 20px;

                img {
                    width: 30px;
                    height: 30px;
                    margin-right: 10px;
                }
            }
        }

        .content-right {

            .right-title {
                margin: 20px;
                font-size: 16px;
                font-weight: bold;
                color: #000000;
            }
        }

        .chat-message-list {
            height: calc(100vh - 420px);
            margin: 20px auto;
            overflow: hidden;
            overflow-y: auto;

            .ai-message,
            .user-message {
                display: flex;
                align-items: start;
                justify-content: end;
                margin-bottom: 20px;

                .message-test {
                    font-size: 16px;
                    color: #3D3D3D;
                    padding: 10px 18px;
                    max-width: 80%;
                    border-radius: 12px;
                    background: #DCECF3;
                }
            }

            .ai-message {
                justify-content: start;
                flex-wrap: wrap;

                .ai-avatar {
                    width: 40px;
                    height: 40px;
                    border-radius: 50%;
                }

                .ai-test {
                    margin-left: 12px;
                    max-width: 80%;
                }

                .ai-research {
                    display: flex;
                    align-items: center;
                    margin-top: 12px;

                    span {
                        color: #FF0000;
                        font-size: 14px;
                        padding: 5px 12px;
                        border-radius: 8px;
                        cursor: pointer;
                        border: 1px solid #FF0000;
                        background: rgba(255, 0, 0, 0.1);

                        &:nth-child(1) {
                            margin-right: 8px;
                            color: #2D66B3;
                            border: 1px solid #2D66B3;
                            background: rgba(45, 102, 179, 0.1);
                        }
                    }
                }

                .ai-assistant {
                    margin-top: 12px;
                    cursor: pointer;

                    .assistant-icon {
                        width: 20px;
                        height: 20px;
                        margin-right: 6px;
                    }
                }
            }
        }
    }
</style>